package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.ComposeOnlineOrder;

/**
 * 
 * @author 
 *
 */
@DAO
public interface ComposeOnlineOrderDAO{
	
	@SQL("SELECT id,orderNo,code,userId,gameId,duration,price,parentName,parentPhone,name,identityCard,teacher,area,school,grade,status,payWay,payOrder,source,subjectId,isExam,composition,isCheck,teacherId,score,isWin,deleteFlag,createAt,createUser,updateAt,updateUser FROM ComposeOnlineOrder WHERE deleteFlag=1 #if(:t.name!=''){ and name like '%##(:t.name)%' } #if(:t.grade!=''){ and grade like '%##(:t.grade)%' } #if(:t.code!=''){ and code like '%##(:t.code)%' } #if(:t.parentPhone!=''){ and parentPhone like '%##(:t.parentPhone)%' } "
			+ "#if(:t.gameId!=-1){ and gameId=:t.gameId } #if(:t.status!=-1){ and status=:t.status } #if(:t.isExam!=-1){ and isExam=:t.isExam } #if(:t.isCheck!=-1){ and isCheck=:t.isCheck } #if(:t.isWin!=-1){ and isWin=:t.isWin } ORDER BY createAt DESC LIMIT :t.start,:t.length ")
    List<ComposeOnlineOrder> query(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("SELECT count(1) FROM ComposeOnlineOrder WHERE deleteFlag=1 #if(:t.name!=''){ and name like '%##(:t.name)%' } #if(:t.grade!=''){ and grade like '%##(:t.grade)%' } #if(:t.code!=''){ and code like '%##(:t.code)%' } #if(:t.parentPhone!=''){ and parentPhone like '%##(:t.parentPhone)%' } "
			+ "#if(:t.gameId!=-1){ and gameId=:t.gameId } #if(:t.status!=-1){ and status=:t.status } #if(:t.isExam!=-1){ and isExam=:t.isExam } #if(:t.isCheck!=-1){ and isCheck=:t.isCheck } #if(:t.isWin!=-1){ and isWin=:t.isWin } ")
	int querysize(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("SELECT a.id,a.orderNo,a.code,a.userId,a.gameId,a.duration,a.price,a.parentName,a.parentPhone,a.name,a.identityCard,a.teacher,a.area,a.school,a.grade,a.status,a.payWay,a.payOrder,a.source,a.subjectId,a.isExam,a.composition,a.isCheck,a.teacherId,a.score,a.deleteFlag,a.createUser,a.updateAt,a.updateUser,b.subjectNo,b.title FROM ComposeOnlineOrder a LEFT JOIN ComposeSubject b ON a.subjectId= b.id WHERE a.deleteFlag=1 "
			+ "#if(:t.name!=''){ and a.name like '%##(:t.name)%' } #if(:t.grade!=''){ and a.grade like '%##(:t.grade)%' } #if(:t.parentName!=''){ and a.parentName like '%##(:t.parentName)%' } #if(:t.parentPhone!=''){ and a.parentPhone like '%##(:t.parentPhone)%' } #if(:t.gameId!=-1){ and a.gameId=:t.gameId } #if(:t.status!=-1){ and a.status=:t.status } #if(:t.isExam!=-1){ and a.isExam=:t.isExam } #if(:t.isCheck!=-1){ and a.isCheck=:t.isCheck } #if(:t.isWin!=-1){ and a.isWin=:t.isWin } #if(:t.teacherId!=-1){ and a.teacherId=:t.teacherId }#else{ and (a.teacherId IS NULL OR a.teacherId='') } ORDER BY a.createAt DESC LIMIT :t.start,:t.length ")
    List<ComposeOnlineOrder> queryQuestion(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("SELECT count(1) FROM ComposeOnlineOrder WHERE deleteFlag=1 #if(:t.name!=''){ and name like '%##(:t.name)%' } #if(:t.grade!=''){ and grade like '%##(:t.grade)%' } #if(:t.parentName!=''){ and parentName like '%##(:t.parentName)%' } #if(:t.parentPhone!=''){ and parentPhone like '%##(:t.parentPhone)%' } "
			+ "#if(:t.gameId!=-1){ and gameId=:t.gameId } #if(:t.status!=-1){ and status=:t.status } #if(:t.isExam!=-1){ and isExam=:t.isExam } #if(:t.isCheck!=-1){ and isCheck=:t.isCheck } #if(:t.isWin!=-1){ and isWin=:t.isWin } #if(:t.teacherId!=-1){ and teacherId=:t.teacherId }#else{ and (teacherId IS NULL OR teacherId='') }")
	int queryQuestionSize(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("SELECT a.id,a.orderNo,a.code,a.userId,a.gameId,a.duration,a.price,a.parentName,a.parentPhone,a.name,a.identityCard,a.teacher,a.area,a.school,a.grade,a.status,a.payWay,a.payOrder,a.source,a.subjectId,a.isExam,a.composition,a.isCheck,a.teacherId,a.score,a.deleteFlag,a.createUser,a.updateAt,a.updateUser,b.subjectNo,b.title FROM ComposeOnlineOrder a LEFT JOIN ComposeSubject b ON a.subjectId= b.id WHERE a.deleteFlag=1 "
			+ "#if(:t.name!=''){ and a.name like '%##(:t.name)%' } #if(:t.grade!=''){ and a.grade like '%##(:t.grade)%' } #if(:t.parentName!=''){ and a.parentName like '%##(:t.parentName)%' } #if(:t.parentPhone!=''){ and a.parentPhone like '%##(:t.parentPhone)%' } #if(:t.gameId!=-1){ and a.gameId=:t.gameId } #if(:t.status!=-1){ and a.status=:t.status } #if(:t.isExam!=-1){ and a.isExam=:t.isExam } #if(:t.isCheck!=-1){ and a.isCheck=:t.isCheck } #if(:t.isWin!=-1){ and a.isWin=:t.isWin } #if(:t.teacherId!=-1){ and a.teacherId=:t.teacherId }#else{ and (a.teacherId IS NULL OR a.teacherId='') } ORDER BY a.createAt DESC LIMIT :t.start,:t.length ")
    List<ComposeOnlineOrder> queryFpglQuestion(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("SELECT count(1) FROM ComposeOnlineOrder WHERE deleteFlag=1 #if(:t.name!=''){ and name like '%##(:t.name)%' } #if(:t.grade!=''){ and grade like '%##(:t.grade)%' } #if(:t.parentName!=''){ and parentName like '%##(:t.parentName)%' } #if(:t.parentPhone!=''){ and parentPhone like '%##(:t.parentPhone)%' } "
			+ "#if(:t.gameId!=-1){ and gameId=:t.gameId } #if(:t.status!=-1){ and status=:t.status } #if(:t.isExam!=-1){ and isExam=:t.isExam } #if(:t.isCheck!=-1){ and isCheck=:t.isCheck } #if(:t.isWin!=-1){ and isWin=:t.isWin } #if(:t.teacherId!=-1){ and teacherId=:t.teacherId }#else{ and (teacherId IS NULL OR teacherId='') }")
	int queryFpglQuestionSize(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
    
    @SQL("SELECT * FROM ComposeOnlineOrder WHERE id=:1")
    ComposeOnlineOrder queryById(int id);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO ComposeOnlineOrder (orderNo,userId,gameId,duration,price,parentName,parentPhone,name,identityCard,teacher,area,school,grade,status,payWay,payOrder,source,subjectId,isExam,composition,isCheck,teacherId,score,isWin,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.orderNo,:t.userId,:t.gameId,:t.duration,:t.price,:t.parentName,:t.parentPhone,:t.name,:t.identityCard,:t.teacher,:t.area,:t.school,:t.grade,:t.status,:t.payWay,:t.payOrder,:t.source,:t.subjectId,:t.isExam,:t.composition,:t.isCheck,:t.teacherId,:t.score,:t.isWin,1,now(),:t.createUser,now(),:t.updateUser)")
    int create(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
    
    @SQL("UPDATE ComposeOnlineOrder SET code=:2 WHERE id=:1 ")
    void updateById(int id,String code);
	
	@SQL("UPDATE ComposeOnlineOrder SET parentName=:t.parentName,parentPhone=:t.parentPhone,name=:t.name,identityCard=:t.identityCard,teacher=:t.teacher,area=:t.area,school=:t.school,grade=:t.grade,payWay=:t.payWay,payOrder=:t.payOrder,source=:t.source,subjectId=:t.subjectId,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
    
    @SQL("UPDATE ComposeOnlineOrder SET deleteFlag=0 WHERE id=:1 ")
    void deleteById(int id);
    
    @SQL("UPDATE ComposeOnlineOrder SET status=:2,source=:3,payWay=:4,payOrder=:5,updateAt=now(),code=:6 WHERE id=:1 ")
    void updateStatusById(int id,int status,int source,int payWay,String payOrder,String code);
    
    @SQL("UPDATE ComposeOnlineOrder SET isExam=:2,isCheck=:3,isWin=:4,updateAt=now() WHERE id=:1 ")
    void updateWinStatusById(int id,int isExam,int isCheck,int isWin);
    
    @SQL("select status from ComposeOnlineOrder where identityCard=:1 ")
	List<Map> getIDCard(String identityCard);
    
    //-----------
    @SQL("SELECT count(*) FROM ComposeOnlineOrder WHERE deleteFlag=1 AND gameId=:1 ")
    int queryCOnlineOrderSize(int gameId);
    
    @SQL("SELECT id,orderNo,code,name,identityCard,parentName,parentPhone,teacher,area,school,grade,status,score FROM ComposeOnlineOrder WHERE deleteFlag=1 AND gameId=:1 ORDER BY score DESC LIMIT :2,:3 ")
    List<Map> queryCOnlineOrderByGameId(int gameId,int start,int length);
    
    //-----------
    @SQL("SELECT id,orderNo,userId,gameId,duration,price,parentName,parentPhone,name,identityCard,teacher,area,school,grade,status,payWay,payOrder,source,subjectId,isExam,composition,isCheck,teacherId,score,isWin,deleteFlag,createAt,createUser,updateAt,updateUser,remark FROM ComposeOnlineOrder WHERE deleteFlag=1 and teacherId=:t.teacherId #if(:t.gameId!=-1){ and gameId=:t.gameId } #if(:t.grade!=''){ and grade like '%##(:t.grade)%' } #if(:t.isCheck!=-1){ and isCheck=:t.isCheck } #if(:t.remark!=''){ and remark=:t.remark } ORDER BY createAt DESC LIMIT :t.start,:t.length ")
    List<ComposeOnlineOrder> queryCheck(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("SELECT count(1) FROM ComposeOnlineOrder WHERE deleteFlag=1 and teacherId=:t.teacherId #if(:t.gameId!=-1){ and gameId=:t.gameId } #if(:t.grade!=''){ and grade like '%##(:t.grade)%' } #if(:t.isCheck!=-1){ and isCheck=:t.isCheck } #if(:t.remark!=''){ and remark=:t.remark } ")
	int queryChecksize(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);
	
	@SQL("UPDATE ComposeOnlineOrder SET isCheck=:t.isCheck,score=:t.score,remark=:t.remark,updateAt=now() WHERE id=:t.id")
    void updateCheckStatus(@SQLParam("t") ComposeOnlineOrder composeOnlineOrder);

	@SQL("UPDATE ComposeOnlineOrder SET teacherId=:2,updateUser=:3,UpdateAt=NOW() WHERE id=:1")
	void updateTeacherId(List<Integer> orderIds, int userId, String acount);

	@SQL("UPDATE ComposeOnlineOrder SET teacherId=null WHERE id=:1")
	void rmTeacherId(int id);
}